package leetcode;

import java.util.HashSet;
import java.util.Set;

public class Happy_Number {
	public boolean isHappy(int n) {
		int pre = 0;
		if(n==0)
			return false;
		int current =0;
		Set<Integer> set = new HashSet<Integer>(); 
		while(n!=1 && !set.contains(n)){
			set.add(n);
			current = 0;
			while(n>0){
				current+=(n%10)*(n%10);
				n/=10;
			}
			n = current;
		}
		if(n==1){
			return true;
			
		} else{
			return false;
		}
	}
	public static void main(String[] argsStrings){
		Happy_Number happy_Number = new Happy_Number();
		System.out.println(happy_Number.isHappy(377));
	}
}
